package com.example.administrator.shzs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.shzs.R;

import java.util.List;
import java.util.Map;

/**
 * 搜索页面 热门搜索列表展示
 */
public class SearchGridviewAdapter extends BaseAdapter {

    private Context context;
    private List<Map<Object,Object>> datalist;

    public SearchGridviewAdapter(Context context, List<Map<Object, Object>> datalist) {
        this.context = context;
        this.datalist = datalist;
    }

    @Override
    public int getCount() {
        return datalist.size();
    }

    @Override
    public Object getItem(int position) {
        return datalist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoler viewHoler = null;

        if (convertView == null){
            convertView  = LayoutInflater.from(context).inflate(R.layout.home_search_gridview_item,null);
            viewHoler = new ViewHoler();
            viewHoler.textView= (TextView) convertView.findViewById(R.id.index_hot_soso_item);
            convertView.setTag(viewHoler);
        }else {
            viewHoler = (ViewHoler) convertView.getTag();
        }

        viewHoler.textView.setText((CharSequence) datalist.get(position).get("name"));

        return convertView;
    }

    class ViewHoler {
        private TextView textView;
    }
}
